package y_ut.dbtools.exp;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import au.com.bytecode.opencsv.CSVWriter;
/**
 * 
 * @author youxz
 *
 */
public class ExpCsvWriter implements IExpWriter {

	private String path;
	
	private CSVWriter writer = null;
	
	
	
	public ExpCsvWriter(String path) {
		super();
		this.path = path;
	}

	@Override
	public boolean open() {
		return false;
	}

	@Override
	public void newTable(String tableName) {
		File file = new File(path);
		if(!file.exists()) file.mkdirs();
		
		try {
			if(writer!=null) writer.close();
			writer = new CSVWriter(new FileWriter(path+File.separator+tableName+".csv"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void writeTableTitle(String[] data) {
		writer.writeNext(data);
	}

	@Override
	public void writeRowData(String[] data) {
		writer.writeNext(data);
	}

	@Override
	public boolean close() {
		try {
			writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return true;
	}

}
